<?php
function CategoryCheck_Parent($id,$str){
		
		$check = mysql_query("SELECT * FROM category WHERE parent = $id");
		if(mysql_num_rows($check)>0){
			$str = "<ul>";
			while($res_s = mysql_fetch_array($check)){
				switch($res_s['type']){
					case 'Y':
						$dim_ = '(Dimmable)';
					break;
					case 'N':
						$dim_ = '(Non Dimmable)';
					break;
					case 'B':
						$dim_ = '(Dimmable/Non Dimmable)';
					break;
					default:
						$dim_ = NULL;
					break;
				}
				$str .= "<li>";
				$str .= "<span>".$res_s['name']."&nbsp;&nbsp;<font>$dim_</font></span>
				<a title=\"Edit\" href=\"?mngr=cat&subpg=add&id=".$res_s['id']."\" class=\"updateLink catedit\"><i class=\"icon-pencil\"></i></a>
				<a href=\"javascript:void(0)\" onclick=\"DelConfirm('led-master.php?mngr=cat&subpg=view&delid=".$res_s['id']."')\" class=\"updateLink catdel\" title=\"Remove\" ><i class=\"icon-trash\"></i></a>";
				$check_in_child = mysql_query("SELECT * FROM category WHERE parent = ".$res_s['id']."");
				if(mysql_num_rows($check_in_child) > 0){
					$ress_c = mysql_fetch_array($check_in_child);
					$str .= CategoryCheck_Parent($res_s['id'],$str);
				}
				$str .= "</li>";
			}
			$str .= "</ul>";
			return $str;
		}
	}
	function RenderTree(){
		$list = mysql_query("SELECT * FROM category WHERE parent is NULL ORDER BY name");	
		if(mysql_num_rows($list)>0){
			$str = "<ul id=\"red\" class=\"treeview-red treeview jcategory\">"; 
			while($ress = mysql_fetch_array($list)){
				$str .=  "<li><span>".$ress['name']."</span><a title=\"Edit\" href=\"?mngr=cat&subpg=add&id=".$ress['id']."\" class=\"updateLink catedit\"><i class=\"icon-pencil\"></i></a>
				<a href=\"javascript:void(0)\" onclick=\"DelConfirm('led-master.php?mngr=cat&subpg=view&delid=".$ress['id']."')\" class=\"updateLink catdel\" title=\"Remove\"><i class=\"icon-trash\"></i></a>".CategoryCheck_Parent($ress['id'],NULL)."</li>";
			}
			return $str .= "</ul>";
		}else{
			return false;
		}
	}
	
	
	function ShowChild_PopUp($id, $cnt){
		$respon = array();
		$check = mysql_query("SELECT * FROM category WHERE parent = $id");
		if(mysql_num_rows($check)>0){
			$str = "<ul>";
			while($res_s = mysql_fetch_array($check)){
				$cnt++;
				$str .= "<li>";
				$str .= "<input type=\"checkbox\" id=\"cat_check_$cnt\" value=\"".$res_s['id']."\" onclick=\"ChooseCategory('".$res_s['name']."',this)\">&nbsp;&nbsp;<span>".$res_s['name']."";
				$check_in_child = mysql_query("SELECT * FROM category WHERE parent = ".$res_s['id']."");
				if(mysql_num_rows($check_in_child) > 0){
					$ress_c = mysql_fetch_array($check_in_child);
					$str .= ShowChild_PopUp($res_s['id'],$cnt);
				}
				$str .= "</li>";
			}
			$str .= "</ul>";
			$respon['str'] = $str;
			$respon['cnt'] = $cnt;
			return $respon;
		}
	}
	
	
	
?>